//app.js
App({
  data: {
    openid: '',
    created: false,
  },
  
  onLaunch: function () {
    if (!wx.cloud) {
      console.error('请使用 2.2.3 或以上的基础库以使用云能力')
    } else {
      wx.cloud.init({
        env: 'cloud1-1gijto24e717d2dd',
        traceUser: true,
      })
    }

    wx.cloud.callFunction({
      name: 'login',
      data: {},
      success: res => {
        console.log(res)
        if (res.result.data.length === 0) {
          this.data.created = false
        } else {
          this.data.openid = res.result.data[0]._openid
          this.data.created = true
        }
        this.globalData = {
          openid: this.data.openid,
          created: this.data.created
        }
      },
      fail: err => {
        console.error('[数据库] [新增记录] 失败：', err)
      }
    })
  }
})


